var Adv_skd=require("./Adv_skd")

var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("GlobalParam"),
    c = e("Util"),
    l = e("GameData"),
    d = e("SkinLevelData"),
    u = (window.wx, cc._decorator),
    p = u.ccclass,
    h = u.property,
    f = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.SignInData = null),
                (t.content = null),
                (t.btn_double = null),
                (t.ItemsParent = null),
                (t.btn_receive = null),
                (t.look_ad_toggle = null),
                (t.isToggleCheck = !0),
                (t.boxImageList = []),
                (t.signIn_index = 0),
                (t.signIn_key = 0),
                (t.isCanSignIn = !1),
                (t.isFirstSingin = !0),
                t
            );
        }
        return (
            a(t, e),
            (t.prototype.onResetView = function () {
                e.prototype.onResetView.call(this),
                    ad.curr_platform == window.ad.Platform.BAI_DU && ad.adInterface.showBanner(),
                    this.init();

                Adv_skd.default.instance.hideAllAdv();
                Adv_skd.default.instance.showGridAdRight();
                Adv_skd.default.instance.showGridAdLeft();
            }),
            (t.prototype.onClickClose = function () {
                Adv_skd.default.instance.hideAllAdv();

                Adv_skd.default.instance.showGridAdLeftOne();
                Adv_skd.default.instance.showGridAdRightOne();
                Adv_skd.default.instance.showInterstitialAd();

                game.AudioManager.playBtnEffect(), this.closeView(!0);
            }),
            (t.prototype.onDisable = function () { }),
            (t.prototype.registerMediator = function () {
                e.prototype.registerMediator.call(this);
            }),
            (t.prototype.removeMediator = function () {
                e.prototype.removeMediator.call(this);
            }),
            (t.prototype.addEvent = function () {
                e.prototype.addEvent.call(this);
                for (var t = 0; t < this.ItemsParent.children.length; t++) {
                    var o = this.ItemsParent.children[t];
                    o.addComponent(cc.Button), o.on(game.EngineEventType.NodeEvent.click, this.onClickItem, this);
                }
                this.btn_double.on(game.EngineEventType.NodeEvent.click, this.onClick_btn_double, this),
                    this.btn_receive.on(game.EngineEventType.NodeEvent.click, this.onClick_btn_receive, this);
                var n = new cc.Component.EventHandler();
                (n.target = this.node),
                    (n.component = "SignInView"),
                    (n.handler = "callback_check"),
                    (n.customEventData = "foobar"),
                    this.look_ad_toggle.checkEvents.push(n);
            }),
            (t.prototype.removeEvent = function () {
                e.prototype.removeEvent.call(this);
                for (var t = 0; t < this.ItemsParent.children.length; t++) {
                    var o = this.ItemsParent.children[t];
                    o.removeComponent(cc.Button), o.off(game.EngineEventType.NodeEvent.click, this.onClickItem, this);
                }
                this.btn_double.off(game.EngineEventType.NodeEvent.click, this.onClick_btn_double, this),
                    this.btn_receive.off(game.EngineEventType.NodeEvent.click, this.onClick_btn_receive, this),
                    (this.look_ad_toggle.checkEvents = []);
            }),
            (t.prototype.init = function () {
                (this.isCache = !1),
                    (this.content = this.node.getChildByName("content")),
                    (this.ItemsParent = this.content.getChildByName("ItemsParent")),
                    (this.btn_double = this.content.getChildByName("btn_double")),
                    (this.look_ad_toggle = this.content.getChildByName("look_ad_toggle").getComponent(cc.Toggle)),
                    (this.btn_receive = this.content.getChildByName("btn_receive")),
                    ad.curr_platform == window.ad.Platform.TOU_TIAO || ad.curr_platform == window.ad.Platform.OPPO
                        ? ((this.look_ad_toggle.node.active = !1),
                          (this.btn_receive.active = !0),
                          this.btn_double.setPosition(cc.v3(400, -50, 0)),
                          this.btn_receive.setPosition(cc.v3(400, 150, 0)),
                          (this.content.getChildByName("ItemsParent").x = -150),
                          (this.content.getChildByName("bg1").x = -150),
                          this.content.getChildByName("btn_close").setPosition(cc.v3(-500, 260, 0)))
                        : (this.isToggleCheck = !0),
                    this.isToggleCheck ? this.look_ad_toggle.check() : this.look_ad_toggle.uncheck(),
                    (this.isToggleCheck = !this.isToggleCheck),
                    this.callback_check(),
                    this.updateView();
            }),
            (t.prototype.callback_check = function () {
                (this.isToggleCheck = !this.isToggleCheck),
                    (this.btn_double.getChildByName("ad_icon").active = this.isToggleCheck),
                    this.isToggleCheck
                        ? ((this.btn_double.getChildByName("btn_sprite").getComponent(cc.Label).string = "双倍领取"),
                          (this.btn_double.getChildByName("btn_sprite").x = 30))
                        : ((this.btn_double.getChildByName("btn_sprite").getComponent(cc.Label).string = "普通领取"),
                          (this.btn_double.getChildByName("btn_sprite").x = 0));
            }),
            (t.prototype.updateView = function () {
                (this.signIn_index = Number(c.default.getItem("signIn_index", "0"))),
                    "false" == c.default.getItem("todatState" + c.default.getTodayStr(), "false")
                        ? (this.isCanSignIn = !0)
                        : ((this.isCanSignIn = !1), (this.signIn_index -= 1)),
                    this.signIn_index >= 7 ? (this.isFirstSingin = !1) : (this.isFirstSingin = !0),
                    (this.signIn_key = this.signIn_index % 7);
                for (var e = 0; e < this.ItemsParent.children.length; e++) {
                    var t = this.ItemsParent.children[e];
                    t.item_index = e;
                    var o = e;
                    this.isFirstSingin || (o = e + 7),
                        (t.children[3].getComponent(cc.Label).string = s.default.SignInData[o].chinese),
                        e != this.ItemsParent.children.length - 1 &&
                            (t.children[0].getComponent(cc.Sprite).spriteFrame =
                                this.boxImageList[s.default.SignInData[o].imageIndex]),
                        e < this.signIn_key
                            ? (t.children[1].active = !0)
                            : e > this.signIn_key
                            ? (t.children[1].active = !1)
                            : this.isCanSignIn
                            ? (t.children[1].active = !1)
                            : (t.children[1].active = !0);
                }
                (this.btn_double.getComponent(cc.Button).interactable = this.isCanSignIn),
                    (this.btn_receive.getComponent(cc.Button).interactable = this.isCanSignIn);
            }),
            (t.prototype.setSignInDate = function () {
                c.default.setItem("todatState" + c.default.getTodayStr(), "true"),
                    c.default.setItem("signIn_index", (this.signIn_index + 1).toString()),
                    this.updateView();
            }),
            (t.prototype.onClickItem = function (e) {
                e.node.item_index == this.signIn_key &&
                    this.isCanSignIn &&
                    (game.AudioManager.playBtnEffect(), this.setSignInDate(), this.GetRewards(1, this.signIn_key + 1));
            }),
            (t.prototype.onClick_btn_double = function () {
                game.AudioManager.playBtnEffect();
                var e = ad.curr_platform === window.ad.Platform.TOU_TIAO;
                if ((game.log("T=> 签到"), e && window.tt.reportAnalytics("QianDao", {}), this.isToggleCheck)) {
                    var t = this;
                    ad.adInterface.showRewardedVideo(null, null, function () {
                        t.setSignInDate(), t.GetRewards(2, t.signIn_key + 1);
                    });
                } else this.isCanSignIn && (this.setSignInDate(), this.GetRewards(1, this.signIn_key + 1));
            }),
            (t.prototype.GetRewards = function (e) {
                var t = null;
                if (
                    ((t = this.isFirstSingin
                        ? s.default.SignInData[this.signIn_key]
                        : s.default.SignInData[this.signIn_key + 7]),
                    ad.curr_platform == window.ad.Platform.TOU_TIAO &&
                        ("fragment" == t.skinType || "skin" == t.skinType))
                ) {
                    for (var o = 0; o < t.skinList.length; o++) {
                        var n = ["蛇蛇 ", "恐龙仔", "财神", "羊羊"],
                            i = t.skinList[o];
                        ("火龙果" != i && "毒蘑菇" != i && "苹果" != i && "魔术牌" != i) ||
                            (t.skinList[o] = n[c.default.randomFrom(0, n.length - 1)]);
                    }
                    console.log(t.skinList);
                }
                if ("coin" == t.skinType) {
                    var a = l.default.instance.getPlayerCoin(),
                        r = t.num * e;
                    l.default.instance.setPlayerCoin(a + r), game.UIManager.instance.showToast("钻石*" + r);
                } else if ("fragment" == t.skinType) {
                    for (
                        var u = c.default.randomFrom(0, t.skinList.length - 1),
                            p = t.skinList[u],
                            h = d.SkinLevelData.instance.skinList,
                            f = 0;
                        f < h.length;
                        f++
                    )
                        if ((y = h[f]).chinese == p) {
                            d.SkinLevelData.instance.add_fragments(y, t.num * e);
                            break;
                        }
                    game.UIManager.instance.showToast(p + "碎片*" + t.num * e);
                } else if ("skin" == t.skinType) {
                    (u = c.default.randomFrom(0, t.skinList.length - 1)),
                        (p = t.skinList[u]),
                        (h = d.SkinLevelData.instance.skinList);
                    for (var _ = 0; _ < h.length; _++) {
                        var y;
                        if ((y = h[_]).chinese == p) {
                            if (!y.isLock) {
                                (y.isLock = !0),
                                    d.SkinLevelData.instance.setSkinIsLock(y.name),
                                    game.UIManager.instance.showToast(p + "已解锁"),
                                    2 == e && d.SkinLevelData.instance.add_fragments(y, 5);
                                break;
                            }
                            d.SkinLevelData.instance.add_fragments(y, 5 * e),
                                game.UIManager.instance.showToast(p + "碎片*" + 5 * e);
                        }
                    }
                }
            }),
            (t.prototype.onClick_btn_receive = function () {
                game.AudioManager.playBtnEffect(),
                    this.isCanSignIn && (this.setSignInDate(), this.GetRewards(1, this.signIn_key + 1));
            }),
            (t.prototype.closeView = function (t) {
                void 0 === t && (t = !1),
                    this.isCanSignIn && (this.setSignInDate(), this.GetRewards(1, this.signIn_key + 1)),
                    e.prototype.closeView.call(this, !0);
            }),
            r([h([cc.SpriteFrame])], t.prototype, "boxImageList", void 0),
            r([p], t)
        );
    })(game.BasePopView);
i.default = f;
